﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mvc.XForms.UI.Settings;
using System.Linq.Expressions;
using System.Web.UI.WebControls;
using Mvc.XForms.Utilities;
using System.Collections.Specialized;

namespace Mvc.XForms.UI {
	public class PagedSortedParameters : IPagedSortedParameters {
		public PagedSortedParameters(NameValueCollection collection, string pageIndexKey, string sortExpressionKey, string sortDirectionKey, int pageSize, string defaultSortExpression, SortDirection defaultSortDirection) {
			// Paging
			PageIndexKey = pageIndexKey;
			PageIndex = this.GetPageIndex(collection);
			PageSize = pageSize;	

			// Sorting
			SortExpressionKey = sortExpressionKey;
			SortDirectionKey = sortDirectionKey;
			SortExpression = this.SortExpressionFromCollection(collection, defaultSortExpression);
			SortDirection = this.SortDirectionFromCollection(collection, defaultSortDirection);
		}

		public string PageIndexKey { get; private set; }
		public int PageIndex { get; private set; }
		public int PageSize { get; private set; }

		public string SortExpressionKey { get; protected set; }
		public string SortDirectionKey { get; protected set; }
		public string SortExpression { get; private set; }
		public SortDirection SortDirection { get; private set; }
	}
}